package com.android.clinic.doctors.app.ui.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.clinic.doctors.app.ClinicDoctorsApplication;
import com.android.clinic.doctors.app.R;
import com.android.clinic.doctors.app.base.BaseFragment;
import com.android.clinic.doctors.app.glide.ImageLoaderUtils;
import com.android.clinic.doctors.app.ui.AboutActivity;
import com.android.clinic.doctors.app.ui.AmendPasswordActivity;
import com.android.clinic.doctors.app.ui.LoginActivity;
import com.android.clinic.doctors.app.ui.widget.AccordionTextView;
import com.android.clinic.doctors.app.ui.widget.UIAlertView;
import com.android.clinic.doctors.app.utils.AppManager;
import com.android.clinic.doctors.app.utils.PermissionUtils;

/**
 * 我的
 * Created by cheng on 2018/6/11.
 */
public class MineFragment extends BaseFragment implements View.OnClickListener {

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        ImageView ivMineHead = findViewById(R.id.iv_mine_head);
        TextView tvMineName = findViewById(R.id.tv_mine_name);
        ImageLoaderUtils.getInstance().loadHeadImage(ClinicDoctorsApplication.getUserInfo().getImgUrl(), ivMineHead);
        tvMineName.setText(ClinicDoctorsApplication.getUserInfo().getName());

        AccordionTextView tvAboutUs = findViewById(R.id.tv_about_us);
        AccordionTextView tvCustomerService = findViewById(R.id.tv_customer_service);
        AccordionTextView tvEditPassword = findViewById(R.id.tv_edit_password);
        LinearLayout layLoginOut = findViewById(R.id.layout_login_out);
        tvAboutUs.setOnClickListener(this);
        tvCustomerService.setOnClickListener(this);
        tvEditPassword.setOnClickListener(this);
        layLoginOut.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            // 关于我们
            case R.id.tv_about_us:
                startToActivity(AboutActivity.class);
                break;
            // 联系客服
            case R.id.tv_customer_service:
                PermissionUtils.applyCallPhone(getActivity(), new PermissionUtils.CallBack() {
                    @Override
                    public void onGuarantee() {
                        UIAlertView.callPhoneDialog(getActivity(), "管家电话", "4001883525");
                    }

                    @Override
                    public void onDeny() {

                    }
                });
                break;
            // 修改密码
            case R.id.tv_edit_password:
                startToActivity(AmendPasswordActivity.class);
                break;
            // 退出登录
            case R.id.layout_login_out:
                UIAlertView.alertDialog(getActivity(), "提示",
                        "是否确认登出!", new UIAlertView.OnThemeDialogListener() {
                            @Override
                            public void OnDismissButton() {

                            }
                            @Override
                            public void OnSureButton() {
                                exit();
                            }
                        },"确定","取消");
                break;
        }
    }

    private void exit(){
        ClinicDoctorsApplication.saveUserInfo(null);
        startActivity(new Intent(getActivity(), LoginActivity.class));
        AppManager.getAppManager().finishAllActivity();
    }
}
